package club.justwill.single.persistence.store;

import club.justwill.single.persistence.document.Stick;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by xiangnan on 16-1-14.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class StickStore extends MongoDbStore<Stick> {
    public List<Stick> searchProjectComments(Long projectId) {
        return mongoTemplate.find(Query.query(Criteria.where("project_id").is(projectId)), Stick.class);
    }

    public List<Stick> searchUserComments(Long userId) {
        return mongoTemplate.find(Query.query(Criteria.where("user_id").is(userId)), Stick.class);
    }

    public Stick getByStickId(String id) {
        return mongoTemplate.findOne(Query.query(Criteria.where("_id").is(id)), Stick.class);
    }
}
